const express = require('express')
const multer = require('multer')
const router = express.Router()
const uploadController = require('../controllers/uploadController')

const upload = multer({
  storage: multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, './upload')
    },
    filename: function (req, file, cb) {
      const fileFormat = file.originalname.split('.')
      cb(null, Date.now() + '.' + fileFormat[fileFormat.length - 1])
    },
  }),
})

router.post('/', upload.single('file'), uploadController.uploadImg)

module.exports = router
